#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>

/*
  homesensornet example sketch
*/

#include "HomeSensorNet.h"

//Ethernet Variables
EthernetUDP Udp;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3F, 0x1A };
boolean ethernetstatus;
byte ip[]         = { 10, 42, 100, 15 };
byte mask[]       = { 255, 255, 0, 0 };
byte gw[]         = { 10, 42, 254, 1 };
byte broadcast[]  = { 10, 42, 255, 255 };
byte serverip[]   = { 10, 42, 240, 1 };

char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
 

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac);
  Udp.begin(9999);
  HomeSensorNet.begin(&Udp,broadcast,1);      //Send udp, to broadcast IP, station ID #1
}

void loop() 
{
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
   {
     Serial.print("Received packet of size ");
     Serial.println(packetSize);
     // read the packet into packetBufffer
     Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
 
   }
   delay(10);
}
